package com.ltv.xiangqiplugin.views;

import java.awt.Container;
import java.awt.Graphics;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import com.ltv.xiangqiplugin.models.Messages;
import com.ltv.xiangqiplugin.utils.XiangPluginConfiguration;

public class AboutView extends JFrame {
	private static AboutView instance;
	private String title;
	
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	private AboutView() {
		super();
		
		//pack();
		setSize(400, 267);
		setResizable(false);
		 this.setLocationRelativeTo(null);
	}
	
	private static void addALabel(String text, Container container) {
		JLabel label = new JLabel("<html><font color=yellow>" + text + "</font></html>");
		label.setVerticalAlignment(SwingConstants.CENTER);
		label.setHorizontalAlignment(SwingConstants.CENTER);
        container.add(label);
    }

	public static AboutView getInstance() {
		if (instance == null) {
			instance = new AboutView();
		}
		return instance;
	}
	
	public void showContent(String title) {
		this.getContentPane().removeAll();
		setTitle(Messages.getInstance().getProperty("menu.help.about") + " " + title);
		JPanel pnl = new JPanel() {

			@Override
			protected void paintComponent(Graphics g) {
				g.drawImage(new ImageIcon(getClass().getResource("/bg/about.jpg")).getImage(), 0, 0, null);
			}
			
		};
		
		pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS));
		
		addALabel(title + " " + Messages.getInstance().getProperty("version") 
				+ " " + XiangPluginConfiguration.getInstance().getPluginVersion(), pnl);
		addALabel(Messages.getInstance().getProperty("copyright") + " " + XiangPluginConfiguration.getInstance().getCopyright(), pnl);
		
		addALabel(Messages.getInstance().getProperty("developed.by"), pnl);
		
		addALabel(XiangPluginConfiguration.getInstance().getLocPX(), pnl);
		addALabel(XiangPluginConfiguration.getInstance().getThongTCM(), pnl);
		addALabel(XiangPluginConfiguration.getInstance().getPhucPD(), pnl);
		
		this.getContentPane().add(pnl);
		setVisible(true);
	}
	
	
}
